package com.llj.project.controller;


import com.alibaba.fastjson.JSON;
import com.llj.project.bean.User;
import com.llj.project.dao.UserDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @RequestMapping("/login")
    public String LoginInformation(@RequestBody User user){

        String flag="error";
        User user1= userDao.getUserByMassage(user.getUsername(),user.getPassword());
        System.out.println("user = " + user1);
        HashMap<String, Object> map = new HashMap<>();
        if (user1!=null){
            flag="ok";
        }
        map.put("flag",flag);
        map.put("user",user);
        String res = JSON.toJSONString(map);
        return res;
    }

    @RequestMapping("/register")
    public String addUser(@RequestBody User user){
        System.out.println("user = " + user);
        int i = userDao.addUser(user);
        return i>0?"success":"error";

    }
}
